1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 import java.awt.*;
31 import java.text.*;
32
33 public class SupplementaryCanDisplayUpToTest {
34
35
36
37 private static String[][] DATA = {
38
39 { "Meiryo", "\ud87e\udd45\ud87e\udd47\udb80\udc00", "4" },
40 { "Meiryo", "\ud87e\udd45\ud87e\udd47\udb80Z", "4" },
41 { "Meiryo", "\ud87e\udd45\ud87e\udd47\udb80", "4" },
42 { "Meiryo", "\ud87e\udd45\ud87e\udd47\udc00", "4" },
43 { "Meiryo", "\ud87e\udd45\ud87e\udd47", "-1" },
44
45
46 { "AR PL UMing TW", "\ud87e\udc25\ud87e\udc3b\udb80\udc00", "4" },
47 { "AR PL UMing TW", "\ud87e\udc25\ud87e\udc3b\udb80Z", "4" },
48 { "AR PL UMing TW", "\ud87e\udc25\ud87e\udc3b\udb80", "4" },
49 { "AR PL UMing TW", "\ud87e\udc25\ud87e\udc3b\udc00", "4" },
50 { "AR PL UMing TW", "\ud87e\udc25\ud87e\udc3b", "-1" },
51
52
53 { "FZMingTi", "\ud87e\udc25\ud87e\udc3b\udb80\udc00", "4" },
54 { "FZMingTi", "\ud87e\udc25\ud87e\udc3b\udb80Z", "4" },
55 { "FZMingTi", "\ud87e\udc25\ud87e\udc3b\udb80", "4" },
56 { "FZMingTi", "\ud87e\udc25\ud87e\udc3b\udc00", "4" },
57 { "FZMingTi", "\ud87e\udc25\ud87e\udc3b", "-1" },
58 };
59 private static int errorcount = 0;
60
61 public static void main(String[] args) {
62 for (String[] data : DATA) {
63 String fontname = data[0];
64 Font font = new Font(fontname, Font.PLAIN, 16);
65 if (font.getFamily().equals(Font.DIALOG)) {
66
67 continue;
68 }
69
70 System.out.printf("Testing with font '%s'... ", fontname);
71 int errors = 0;
72 String text = data[1];
73 int expected = Integer.parseInt(data[2]);
74
75 int result = font.canDisplayUpTo(text);
76 if (result != expected) {
77 System.err.println("canDisplayUpTo(String) returns " + result);
78 errors++;
79 }
80
81 result = font.canDisplayUpTo(text.toCharArray(), 0, text.length());
82 if (result != expected) {
83 System.err.println("canDisplayUpTo(char[], int, int) returns " + result);
84 errors++;
85 }
86
87 CharacterIterator iter = new StringCharacterIterator(text);
88 result = font.canDisplayUpTo(iter, iter.getBeginIndex(), iter.getEndIndex());
89 if (result != expected) {
90 System.err.println("canDisplayUpTo(CharacterIterator, int, int) returns " + result);
91 errors++;
92 }
93
94 if (errors == 0) {
95 System.out.println("passed");
96 } else {
97 System.out.println("failed");
98 errorcount += errors;
99 }
100 }
101 if (errorcount > 0) {
102 throw new RuntimeException("SupplementaryCanDisplayUpToTest: failed");
103 }
104 }
105 }